//服务器地址
const baseUrl = "http://localhost:8001";
/**
 * get请求
 */
function getRequest(url, params) {
  /**
   * 加载请求提示
   */
  wx.showLoading({
    title: '加载中...',
    mask: true
  })
  let promise = new Promise((resolve, reject) => {
    wx.request({
      url: url,
      method: "GET",
      data: params,
      header: {
        "Content-Type": 'application/json'
      },
      success: res => {
        resolve(res.data)
      },
      fail: err => {
        reject(err)
      },
      complete: () => {
        wx.hideLoading();
      }
    })
  })
  return promise;
}
/**
 * post请求
 */
function postRequest(url, params) {
  /**
   * 加载请求提示
   */
  wx.showLoading({
    title: '加载中...',
    mask: true
  })
  let promise = new Promise((resolve, reject) => {
    wx.request({
      url: url,
      method: "POST",
      data: params,
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: res => {
        resolve(res.data)
      },
      fail: err => {
        reject(err)
      },
      complete: () => {
        wx.hideLoading();
      }
    })
  })
  return promise;
}
module.exports = {
  baseUrl,
  getRequest,
  postRequest
}